<template>
  <div>
    <div class="form">
      <el-form ref="form" style="width: 600px;" :model="form" label-width="80px">
        <el-form-item label="教室名称">
          <el-input v-model="form.name" placeholder="教室名称"></el-input>
        </el-form-item>
        <el-form-item label="教室容量">
          <el-input v-model="form.name" placeholder="教室容量"></el-input>
        </el-form-item>
<!--        <el-form-item label="课程名称">-->
<!--          <el-input v-model="form.name" placeholder="课程名称"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="使用时间">
          <el-col :span="11">
            <el-date-picker  type="datetime" placeholder="选择时间" v-model="form.date1" style="width: 100%;"></el-date-picker>
          </el-col>
          <el-col class="line" style="text-align: center" :span="2"> 到</el-col>
          <el-col :span="11">
            <el-date-picker  type="datetime" placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="教室" v-if="false">
          <el-col class="line" style="text-align: center" :span="2"> 宽</el-col>
          <el-col :span="8">
            <el-input v-model="width"></el-input>
          </el-col>
          <el-col class="line" style="text-align: center" :span="2"> 高</el-col>
          <el-col :span="8">
            <el-input v-model="height"></el-input>
          </el-col>
          <el-col :span="4">
            <el-button @click="generate" style="margin-left: 10px" type="info" class="defaultBtn">生成</el-button>
          </el-col>
        </el-form-item>
      </el-form>
    </div>
    <div v-if="isTrue">
      <div class="header">
        <div class="title">讲台</div>
      </div>
      <div class="tip">
        单击页面中设置座位，空白地方未设置默认为走廊
      </div>
      <table>
        <tr class="tr-item" v-for="(row,index) in matrix" :key="index">
          <td class="item" :class="{itemActive:cell.status===1}" @click="getItemBox(index,cell,indexs)" v-for="(cell,indexs) in row" :key="indexs"></td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      matrix: [],
      width:25,
      height:10,
      isTrue:true,
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      }
    };
  },
  created() {
    this.generateMatrix();
  },
  mounted() {
    // this.getIndex()
  },
  methods: {
    generate(){
      if (this.height && this.width){
        this.generateMatrix()
        this.isTrue=true
      }else{
        this.height=10
        this.width=25
        this.generateMatrix()
        this.isTrue=true
      }
    },

    generateMatrix() {
      this.matrix = [];
      for (let i = 0; i < this.height; i++) {
        let row = [];
        for (let j = 0; j < this.width; j++) {
          row.push({id:i * 10 + j,name:'张三',state:1,status:0});
        }
        this.matrix.push(row);
      }
      // console.log(this.matrix)
    },

    getIndex(){
      console.log(this.matrix)
      let font={row:1,index:2}

    },

    getItemBox(row,item,index){
      console.log(row,item,index)
      console.log(this.matrix)
      this.matrix.forEach((value,itemIndex)=>{
        value.forEach((value1,index1)=>{
          // console.log(itemIndex,value1,index1)
          if (itemIndex===row && index===index1){
            console.log(value1)
            value1.status===1 ? value1.status = 0:value1.status = 1
          }
        })
      })
    },
    submit(){
      console.log(this.matrix)
    }
  }
};
</script>
<style lang="scss">
.header{
  width: 100%;
  display: flex;
  justify-content: center;
  .title{
    width: 150px;
    height: 40px;
    text-align: center;
    border: 1px solid #f6f6f6;
    line-height: 40px;
    margin-bottom: 20px;
  }
}
.tip{
  width: 100%;
  font-size: 12px;
  margin-bottom: 15px;
}
.tr-item{
  margin: 10px;
  .item{
    width: 40px;
    height: 40px;
    border-radius: 5px;
    border: 1px solid #f6f5f6;
    margin: 40px;
    text-align: center;
  }
  .itemActive{
    background: #ff5246;
    border: 1px solid #ff5246;
  }
}

</style>
